<!DOCTYPE html>
<html lang="en-US">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>用户中心kratos | anyang的博客</title>
    <meta name="description" content="千里之行,始于足下">
    <meta name="generator" content="VuePress 1.3.1">
    <link rel="icon" href="/img/favicon.ico">
  <script charset="utf-8" src="/js/main.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.slim.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/fancybox/3.5.2/jquery.fancybox.min.js"></script>
  <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/fancybox/3.5.2/jquery.fancybox.min.css">
  <meta name="keywords" content="福小林,奔奔,ourLang,CentOS,JAVA,vue组件,lsdCloud">
  <script async="async" src="https://www.googletagmanager.com/gtag/js?id=UA-146891701-1"></script>
  <script>window.dataLayer = window.dataLayer || [];
      function gtag(){dataLayer.push(arguments);}
      gtag('js', new Date());
    
      gtag('config', 'UA-146891701-1');</script>
  <script>var _hmt = _hmt || [];
      (function() {
        var hm = document.createElement("script");
        hm.src = "https://hm.baidu.com/hm.js?56eae8eec590ccaef1d5ff99d766f315";
        var s = document.getElementsByTagName("script")[0]; 
        s.parentNode.insertBefore(hm, s);
      })();</script>
    
    <link rel="preload" href="/assets/css/0.styles.9fff9873.css" as="style"><link rel="preload" href="/assets/js/app.1bc80adb.js" as="script"><link rel="preload" href="/assets/js/2.7c0608ab.js" as="script"><link rel="preload" href="/assets/js/36.961a1c50.js" as="script"><link rel="prefetch" href="/assets/js/10.81caa2ab.js"><link rel="prefetch" href="/assets/js/100.05bb269d.js"><link rel="prefetch" href="/assets/js/101.3e18b4d6.js"><link rel="prefetch" href="/assets/js/102.c7d7ed9c.js"><link rel="prefetch" href="/assets/js/103.4c771ce7.js"><link rel="prefetch" href="/assets/js/104.a2acd367.js"><link rel="prefetch" href="/assets/js/105.63399350.js"><link rel="prefetch" href="/assets/js/106.8a4744cc.js"><link rel="prefetch" href="/assets/js/107.7739d796.js"><link rel="prefetch" href="/assets/js/108.8008ae33.js"><link rel="prefetch" href="/assets/js/109.01c63898.js"><link rel="prefetch" href="/assets/js/11.7b837560.js"><link rel="prefetch" href="/assets/js/110.ad01aca9.js"><link rel="prefetch" href="/assets/js/111.3d74db70.js"><link rel="prefetch" href="/assets/js/112.67f55c34.js"><link rel="prefetch" href="/assets/js/113.016cd3c0.js"><link rel="prefetch" href="/assets/js/114.860e4b2b.js"><link rel="prefetch" href="/assets/js/115.b2f26258.js"><link rel="prefetch" href="/assets/js/116.8bea67b4.js"><link rel="prefetch" href="/assets/js/117.20682843.js"><link rel="prefetch" href="/assets/js/118.86a22e16.js"><link rel="prefetch" href="/assets/js/119.ad518bea.js"><link rel="prefetch" href="/assets/js/12.8fd78714.js"><link rel="prefetch" href="/assets/js/120.f97dd86f.js"><link rel="prefetch" href="/assets/js/121.c5601b4a.js"><link rel="prefetch" href="/assets/js/122.2889645a.js"><link rel="prefetch" href="/assets/js/13.ebf26820.js"><link rel="prefetch" href="/assets/js/14.b92dca09.js"><link rel="prefetch" href="/assets/js/15.b3dcef45.js"><link rel="prefetch" href="/assets/js/16.50378990.js"><link rel="prefetch" href="/assets/js/17.056bba2b.js"><link rel="prefetch" href="/assets/js/18.9047bb38.js"><link rel="prefetch" href="/assets/js/19.ab53b0fe.js"><link rel="prefetch" href="/assets/js/20.fe0b8af0.js"><link rel="prefetch" href="/assets/js/21.20a702f3.js"><link rel="prefetch" href="/assets/js/22.0ee08d29.js"><link rel="prefetch" href="/assets/js/23.02039a9a.js"><link rel="prefetch" href="/assets/js/24.363d3d74.js"><link rel="prefetch" href="/assets/js/25.dd6b101e.js"><link rel="prefetch" href="/assets/js/26.20493714.js"><link rel="prefetch" href="/assets/js/27.708723e5.js"><link rel="prefetch" href="/assets/js/28.4561834a.js"><link rel="prefetch" href="/assets/js/29.15cfcf5f.js"><link rel="prefetch" href="/assets/js/3.8d39d40c.js"><link rel="prefetch" href="/assets/js/30.04ab69de.js"><link rel="prefetch" href="/assets/js/31.b11c4302.js"><link rel="prefetch" href="/assets/js/32.81ae74ee.js"><link rel="prefetch" href="/assets/js/33.ddf09cc0.js"><link rel="prefetch" href="/assets/js/34.bc3549f7.js"><link rel="prefetch" href="/assets/js/35.4a0e0ebd.js"><link rel="prefetch" href="/assets/js/37.d8658de5.js"><link rel="prefetch" href="/assets/js/38.f76063aa.js"><link rel="prefetch" href="/assets/js/39.73edd08f.js"><link rel="prefetch" href="/assets/js/4.916af9bf.js"><link rel="prefetch" href="/assets/js/40.72314bff.js"><link rel="prefetch" href="/assets/js/41.c5eb1147.js"><link rel="prefetch" href="/assets/js/42.07aeafbb.js"><link rel="prefetch" href="/assets/js/43.c4a652ba.js"><link rel="prefetch" href="/assets/js/44.91fbe22b.js"><link rel="prefetch" href="/assets/js/45.6eecf0c4.js"><link rel="prefetch" href="/assets/js/46.81b7f108.js"><link rel="prefetch" href="/assets/js/47.b4468ab3.js"><link rel="prefetch" href="/assets/js/48.df205f23.js"><link rel="prefetch" href="/assets/js/49.7df59fa3.js"><link rel="prefetch" href="/assets/js/5.4fcd540a.js"><link rel="prefetch" href="/assets/js/50.0dc2fc5b.js"><link rel="prefetch" href="/assets/js/51.1ffabe54.js"><link rel="prefetch" href="/assets/js/52.2269d284.js"><link rel="prefetch" href="/assets/js/53.81b23843.js"><link rel="prefetch" href="/assets/js/54.b3249def.js"><link rel="prefetch" href="/assets/js/55.50dcf2af.js"><link rel="prefetch" href="/assets/js/56.c399c272.js"><link rel="prefetch" href="/assets/js/57.024f1dbb.js"><link rel="prefetch" href="/assets/js/58.680c6cf4.js"><link rel="prefetch" href="/assets/js/59.2291e9d7.js"><link rel="prefetch" href="/assets/js/6.7610d1d4.js"><link rel="prefetch" href="/assets/js/60.e59a26c1.js"><link rel="prefetch" href="/assets/js/61.ff5c64e4.js"><link rel="prefetch" href="/assets/js/62.7d97062c.js"><link rel="prefetch" href="/assets/js/63.6456dc7e.js"><link rel="prefetch" href="/assets/js/64.0b055680.js"><link rel="prefetch" href="/assets/js/65.9f25601c.js"><link rel="prefetch" href="/assets/js/66.cd973084.js"><link rel="prefetch" href="/assets/js/67.9b8f9716.js"><link rel="prefetch" href="/assets/js/68.d6c1869a.js"><link rel="prefetch" href="/assets/js/69.0a3688dd.js"><link rel="prefetch" href="/assets/js/7.9ebbd956.js"><link rel="prefetch" href="/assets/js/70.22f48891.js"><link rel="prefetch" href="/assets/js/71.9eb4fda9.js"><link rel="prefetch" href="/assets/js/72.ca4fa80c.js"><link rel="prefetch" href="/assets/js/73.17d1ab37.js"><link rel="prefetch" href="/assets/js/74.139691db.js"><link rel="prefetch" href="/assets/js/75.08d0560f.js"><link rel="prefetch" href="/assets/js/76.61078c10.js"><link rel="prefetch" href="/assets/js/77.4482adcc.js"><link rel="prefetch" href="/assets/js/78.166f2c37.js"><link rel="prefetch" href="/assets/js/79.2c7d6b79.js"><link rel="prefetch" href="/assets/js/8.6f8916c2.js"><link rel="prefetch" href="/assets/js/80.80445c3f.js"><link rel="prefetch" href="/assets/js/81.14e3bae8.js"><link rel="prefetch" href="/assets/js/82.7dac687f.js"><link rel="prefetch" href="/assets/js/83.1dd2e78e.js"><link rel="prefetch" href="/assets/js/84.23b759de.js"><link rel="prefetch" href="/assets/js/85.7574f69f.js"><link rel="prefetch" href="/assets/js/86.102dac61.js"><link rel="prefetch" href="/assets/js/87.8f5d639e.js"><link rel="prefetch" href="/assets/js/88.e564cbbe.js"><link rel="prefetch" href="/assets/js/89.cd66eb78.js"><link rel="prefetch" href="/assets/js/9.baa162db.js"><link rel="prefetch" href="/assets/js/90.685c6878.js"><link rel="prefetch" href="/assets/js/91.b8d1b7ea.js"><link rel="prefetch" href="/assets/js/92.1faa374d.js"><link rel="prefetch" href="/assets/js/93.cf5ff33c.js"><link rel="prefetch" href="/assets/js/94.8a02aefb.js"><link rel="prefetch" href="/assets/js/95.1b379a5b.js"><link rel="prefetch" href="/assets/js/96.9fd67185.js"><link rel="prefetch" href="/assets/js/97.c5a6a5a1.js"><link rel="prefetch" href="/assets/js/98.9a231411.js"><link rel="prefetch" href="/assets/js/99.5b344cab.js">
    <link rel="stylesheet" href="/assets/css/0.styles.9fff9873.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container"><header class="navbar"><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/" class="home-link router-link-active"><!----> <span class="site-name">anyang的博客</span></a> <div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/" class="nav-link">
  主页
</a></div><div class="nav-item"><a href="/study-guide/introduction.html" class="nav-link">
  学习指南
</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="技术分类" class="dropdown-title"><span class="title">技术分类</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/java/introduction.html" class="nav-link">
  Java
</a></li><li class="dropdown-item"><!----> <a href="/go/introduction.html" class="nav-link">
  Go
</a></li><li class="dropdown-item"><!----> <a href="/sql/introduction.html" class="nav-link">
  SQL
</a></li><li class="dropdown-item"><!----> <a href="/fhir/introduction.html" class="nav-link">
  FHIR
</a></li></ul></div></div><div class="nav-item"><a href="/blog/introduction.html" class="nav-link">
  个人博客
</a></div><div class="nav-item"><a href="/tool/developmentBox.html" class="nav-link">
  开发百宝箱
</a></div><div class="nav-item"><a href="/project/introduction.html" class="nav-link">
  项目分享
</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="了解更多" class="dropdown-title"><span class="title">了解更多</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="http://wpa.qq.com/msgrd?v=3&amp;uin=1300378587&amp;site=qq&amp;menu=yes" target="_blank" rel="noopener noreferrer" class="nav-link external">
  其他合作
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li><li class="dropdown-item"><!----> <a href="http://www.lsdcloud.com/" target="_blank" rel="noopener noreferrer" class="nav-link external">
  友情网站
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li><li class="dropdown-item"><!----> <a href="https://github.com/ourlang" target="_blank" rel="noopener noreferrer" class="nav-link external">
  Github
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li><li class="dropdown-item"><!----> <a href="https://gitee.com/anlexanyang" target="_blank" rel="noopener noreferrer" class="nav-link external">
  码云
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li><li class="dropdown-item"><!----> <a href="https://blog.csdn.net/qq_37493556" target="_blank" rel="noopener noreferrer" class="nav-link external">
  CSDN
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li></ul></div></div><div class="nav-item"><a href="/linkExchanges/introduction.html" class="nav-link">
  友情链接
</a></div> <!----></nav></div></header> <div class="sidebar-mask"></div> <aside class="sidebar"><nav class="nav-links"><div class="nav-item"><a href="/" class="nav-link">
  主页
</a></div><div class="nav-item"><a href="/study-guide/introduction.html" class="nav-link">
  学习指南
</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="技术分类" class="dropdown-title"><span class="title">技术分类</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/java/introduction.html" class="nav-link">
  Java
</a></li><li class="dropdown-item"><!----> <a href="/go/introduction.html" class="nav-link">
  Go
</a></li><li class="dropdown-item"><!----> <a href="/sql/introduction.html" class="nav-link">
  SQL
</a></li><li class="dropdown-item"><!----> <a href="/fhir/introduction.html" class="nav-link">
  FHIR
</a></li></ul></div></div><div class="nav-item"><a href="/blog/introduction.html" class="nav-link">
  个人博客
</a></div><div class="nav-item"><a href="/tool/developmentBox.html" class="nav-link">
  开发百宝箱
</a></div><div class="nav-item"><a href="/project/introduction.html" class="nav-link">
  项目分享
</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="了解更多" class="dropdown-title"><span class="title">了解更多</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="http://wpa.qq.com/msgrd?v=3&amp;uin=1300378587&amp;site=qq&amp;menu=yes" target="_blank" rel="noopener noreferrer" class="nav-link external">
  其他合作
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li><li class="dropdown-item"><!----> <a href="http://www.lsdcloud.com/" target="_blank" rel="noopener noreferrer" class="nav-link external">
  友情网站
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li><li class="dropdown-item"><!----> <a href="https://github.com/ourlang" target="_blank" rel="noopener noreferrer" class="nav-link external">
  Github
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li><li class="dropdown-item"><!----> <a href="https://gitee.com/anlexanyang" target="_blank" rel="noopener noreferrer" class="nav-link external">
  码云
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li><li class="dropdown-item"><!----> <a href="https://blog.csdn.net/qq_37493556" target="_blank" rel="noopener noreferrer" class="nav-link external">
  CSDN
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li></ul></div></div><div class="nav-item"><a href="/linkExchanges/introduction.html" class="nav-link">
  友情链接
</a></div> <!----></nav>  <ul class="sidebar-links"><li><a href="/blog/introduction.html" class="sidebar-link">博主介绍</a></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading open"><span>Go</span> <span class="arrow down"></span></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/blog/Go/11  需求规格说明书.html" class="sidebar-link">权限需求规格说明书</a></li><li><a href="/blog/Go/12  用户中心kratos.html" class="active sidebar-link">用户中心kratos</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/blog/Go/12  用户中心kratos.html#_1-代码下载" class="sidebar-link">1 代码下载</a></li><li class="sidebar-sub-header"><a href="/blog/Go/12  用户中心kratos.html#_2-安装数据库连接环境" class="sidebar-link">2 安装数据库连接环境</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/blog/Go/12  用户中心kratos.html#_2-1-安装环境必需的依赖项" class="sidebar-link">2.1 安装环境必需的依赖项</a></li><li class="sidebar-sub-header"><a href="/blog/Go/12  用户中心kratos.html#_2-2-数据库readme" class="sidebar-link">2.2 数据库README</a></li><li class="sidebar-sub-header"><a href="/blog/Go/12  用户中心kratos.html#_2-3-pop基础安装及使用" class="sidebar-link">2.3 pop基础安装及使用</a></li></ul></li><li class="sidebar-sub-header"><a href="/blog/Go/12  用户中心kratos.html#_3-golang操作数据库说明" class="sidebar-link">3 Golang操作数据库说明</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/blog/Go/12  用户中心kratos.html#_3-1-连接数据库" class="sidebar-link">3.1 连接数据库</a></li><li class="sidebar-sub-header"><a href="/blog/Go/12  用户中心kratos.html#_3-2-创建新纪录" class="sidebar-link">3.2 创建新纪录</a></li><li class="sidebar-sub-header"><a href="/blog/Go/12  用户中心kratos.html#_3-3-按-id-查询一条记录" class="sidebar-link">3.3 按 ID 查询一条记录</a></li><li class="sidebar-sub-header"><a href="/blog/Go/12  用户中心kratos.html#_3-4-查询所有记录" class="sidebar-link">3.4 查询所有记录</a></li><li class="sidebar-sub-header"><a href="/blog/Go/12  用户中心kratos.html#_3-5-模糊查询某些数据" class="sidebar-link">3.5 模糊查询某些数据</a></li><li class="sidebar-sub-header"><a href="/blog/Go/12  用户中心kratos.html#_3-6-更新单个记录" class="sidebar-link">3.6 更新单个记录</a></li><li class="sidebar-sub-header"><a href="/blog/Go/12  用户中心kratos.html#_3-7-更新多个记录" class="sidebar-link">3.7 更新多个记录</a></li><li class="sidebar-sub-header"><a href="/blog/Go/12  用户中心kratos.html#_3-8-删除单个记录" class="sidebar-link">3.8 删除单个记录</a></li></ul></li><li class="sidebar-sub-header"><a href="/blog/Go/12  用户中心kratos.html#_4-迁移kratos项目的数据到mysql" class="sidebar-link">4 迁移kratos项目的数据到mysql</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/blog/Go/12  用户中心kratos.html#_4-1-用navicat创建一个数据库kratos" class="sidebar-link">4.1 用Navicat创建一个数据库kratos</a></li><li class="sidebar-sub-header"><a href="/blog/Go/12  用户中心kratos.html#_4-2-进行kratos项目数据迁移" class="sidebar-link">4.2 进行kratos项目数据迁移</a></li></ul></li><li class="sidebar-sub-header"><a href="/blog/Go/12  用户中心kratos.html#_5-编译kratos" class="sidebar-link">5 编译kratos</a></li><li class="sidebar-sub-header"><a href="/blog/Go/12  用户中心kratos.html#_6-启动kratos项目" class="sidebar-link">6 启动kratos项目</a></li><li class="sidebar-sub-header"><a href="/blog/Go/12  用户中心kratos.html#_7-绑定前端页面" class="sidebar-link">7 绑定前端页面</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/blog/Go/12  用户中心kratos.html#_7-1-前端文件结构说明" class="sidebar-link">7.1 前端文件结构说明</a></li><li class="sidebar-sub-header"><a href="/blog/Go/12  用户中心kratos.html#_7-2-前端启动" class="sidebar-link">7.2 前端启动</a></li></ul></li><li class="sidebar-sub-header"><a href="/blog/Go/12  用户中心kratos.html#_8-后台数据库说明" class="sidebar-link">8 后台数据库说明</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/blog/Go/12  用户中心kratos.html#_8-1-邮件消息表courier-messages" class="sidebar-link">8.1 邮件消息表courier_messages</a></li><li class="sidebar-sub-header"><a href="/blog/Go/12  用户中心kratos.html#_8-2-身份表identities" class="sidebar-link">8.2 身份表identities</a></li><li class="sidebar-sub-header"><a href="/blog/Go/12  用户中心kratos.html#_8-3-身份标识符" class="sidebar-link">8.3 身份标识符</a></li><li class="sidebar-sub-header"><a href="/blog/Go/12  用户中心kratos.html#_8-4-身份类型" class="sidebar-link">8.4 身份类型</a></li><li class="sidebar-sub-header"><a href="/blog/Go/12  用户中心kratos.html#_8-5-身份证数据表" class="sidebar-link">8.5 身份证数据表</a></li><li class="sidebar-sub-header"><a href="/blog/Go/12  用户中心kratos.html#_8-6-迁移记录表" class="sidebar-link">8.6 迁移记录表</a></li><li class="sidebar-sub-header"><a href="/blog/Go/12  用户中心kratos.html#_8-7-自助服务错误表" class="sidebar-link">8.7 自助服务错误表</a></li><li class="sidebar-sub-header"><a href="/blog/Go/12  用户中心kratos.html#_8-8-登录请求方法记录表" class="sidebar-link">8.8 登录请求方法记录表</a></li><li class="sidebar-sub-header"><a href="/blog/Go/12  用户中心kratos.html#_8-9-登录请求记录表" class="sidebar-link">8.9 登录请求记录表</a></li><li class="sidebar-sub-header"><a href="/blog/Go/12  用户中心kratos.html#_8-10-配置文件管理请求" class="sidebar-link">8.10 配置文件管理请求</a></li><li class="sidebar-sub-header"><a href="/blog/Go/12  用户中心kratos.html#_8-11-注册请求方法记录表" class="sidebar-link">8.11 注册请求方法记录表</a></li><li class="sidebar-sub-header"><a href="/blog/Go/12  用户中心kratos.html#_8-12-注册请求记录表" class="sidebar-link">8.12 注册请求记录表</a></li><li class="sidebar-sub-header"><a href="/blog/Go/12  用户中心kratos.html#_8-13-sessions" class="sidebar-link">8.13 sessions</a></li></ul></li><li class="sidebar-sub-header"><a href="/blog/Go/12  用户中心kratos.html#_9-kratos项目swagger详解" class="sidebar-link">9 Kratos项目swagger详解</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/blog/Go/12  用户中心kratos.html#_9-1-项目请求api列表" class="sidebar-link">9.1 项目请求API列表</a></li></ul></li><li class="sidebar-sub-header"><a href="/blog/Go/12  用户中心kratos.html#_10-测试服务" class="sidebar-link">10 测试服务</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/blog/Go/12  用户中心kratos.html#_10-1-跳转登录页面" class="sidebar-link">10.1 跳转登录页面</a></li></ul></li><li class="sidebar-sub-header"><a href="/blog/Go/12  用户中心kratos.html#_11-更多资料参考" class="sidebar-link">11 更多资料参考</a></li></ul></li><li><a href="/blog/Go/13  权限服务器keto.html" class="sidebar-link">权限服务器keto</a></li><li><a href="/blog/Go/14  Hydra项目介绍.html" class="sidebar-link">Hydra项目介绍</a></li></ul></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>Java</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>CentOS</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>数据库</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>正则表达式</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>版本控制器</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>ElasticSearch</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>Spring Cloud Alibaba</span> <span class="arrow right"></span></p> <!----></section></li></ul> </aside> <main class="page"> <div class="theme-default-content content__default"><h1 id="用户中心kratos"><a href="#用户中心kratos" class="header-anchor">#</a> 用户中心kratos</h1> <div class="custom-block danger"><p class="custom-block-title">kratos介绍</p> <p>ORY Kratos是根据<a href="https://www.ory.sh/docs/ecosystem/software-architecture-philosophy" target="_blank" rel="noopener noreferrer">云架构最佳实践<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a>构建的<code>API</code>优先身份和用户管理系统。它实现了几乎每个软件应用程序都需要处理的核心用例：</p> <ul><li>自助登录和注册:允许最终用户使用用户名/电子邮件和密码组合,社交登录(使用<code>Google，GitHub</code>登录),无密码流等创建和登录帐户(我们称其为<code>idents</code>)</li> <li>多重身份验证(MFA/2FA):支持协议,例如<code>TOTP([RFC 6238](https://tools.ietf.org/html/rfc6238)和[ IETF RFC 4226](https://tools.ietf.org/html/rfc4226)更好地称为 [Google Authenticator](https://en.wikipedia.org/wiki/Google_Authenticator))</code></li> <li>帐户验证:验证电子邮件地址,电话号码或实际地址实际上属于该身份。</li> <li>帐户恢复:使用&quot;忘记密码&quot;流,安全代码(如果丢失<code>MKFA</code>设备)和其他内容来恢复访问权限。</li> <li>个人资料和帐户管理:使用安全流程更新密码,个人详细信息,电子邮件地址,链接的社交个人资料。</li> <li>管理员API:导入,更新,删除身份。</li></ul></div> <h2 id="_1-代码下载"><a href="#_1-代码下载" class="header-anchor">#</a> 1 代码下载</h2> <p><a href="https://github.com/ory/kratos" target="_blank" rel="noopener noreferrer">kratos源码地址下载<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></p> <div class="custom-block tip"><p class="custom-block-title">解压说明</p> <p><strong>把下载的源码解压后放在本地<code>%GOPATH%/src</code>目录下</strong></p> <p><strong>注:GOPATH为项目的运行时的工作空间位置,GOPATH其中包含三个子目录如下</strong></p> <ul><li>src 目录包含Go的源文件，它们被组织成包（每个目录都对应一个包）</li> <li>pkg 目录包含包对象</li> <li>bin 目录包含可执行命令</li></ul></div> <p><a data-fancybox="" title="kratos存放位置" href="/img/goImage/kratos1.png"><img src="/img/goImage/kratos1.png" alt="kratos存放位置"></a></p> <h2 id="_2-安装数据库连接环境"><a href="#_2-安装数据库连接环境" class="header-anchor">#</a> 2 安装数据库连接环境</h2> <blockquote><p><strong>特别注意：从2019年12月1日开始，Buffalo和所有相关软件包都需要Go Modules，并且GOPATH不再支持使用该模块。$GOPATH$并且最低Go版本为1.13</strong><a href="https://blog.gobuffalo.io/the-road-to-1-0-requiring-modules-5672c6b015e5" target="_blank" rel="noopener noreferrer">具体说明链接<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></p></blockquote> <h3 id="_2-1-安装环境必需的依赖项"><a href="#_2-1-安装环境必需的依赖项" class="header-anchor">#</a> 2.1 安装环境必需的依赖项</h3> <ul><li>可行的Go环境</li> <li>已配置的$PATH环境变量，包括$GOPATH/bin。</li> <li>转到版本&gt;=1.13。</li></ul> <h3 id="_2-2-数据库readme"><a href="#_2-2-数据库readme" class="header-anchor">#</a> 2.2 数据库README</h3> <blockquote><p>说明文件在<code>%GOPATH%\src\kratos\contrib\sql\README.md</code> 翻译如下图：</p></blockquote> <p><a data-fancybox="" title="数据库迁移说明" href="/img/goImage/fizz.png"><img src="/img/goImage/fizz.png" alt="数据库迁移说明"></a> <strong>具体Fizz语法请参考</strong><a href="https://gobuffalo.io/en/docs/db/fizz/" target="_blank" rel="noopener noreferrer">gobuffalo.io<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></p> <h3 id="_2-3-pop基础安装及使用"><a href="#_2-3-pop基础安装及使用" class="header-anchor">#</a> 2.3 pop基础安装及使用</h3> <blockquote><p>pop 是 gobuffalo 默认的 orm 包，当然也可以在其他项目使用 pop。但是 pop 官方强调自己不是 orm，只是具备 orm 的功能。</p></blockquote> <div class="custom-block tip"><p class="custom-block-title">pop主要优点</p> <ul><li>CRUD 操作</li> <li>代码定义模型</li> <li>用于创建，删除和修改的迁移工具</li> <li>数据库支持：PostgreSQL，MySQL，SQLite</li> <li>ActiveRecord UUID 模式</li> <li>YAML 配置</li> <li>易于环境变量使用</li> <li>创建和更新每条记录的时间戳</li> <li>支持事务</li></ul></div> <h4 id="_2-3-1-soda安装"><a href="#_2-3-1-soda安装" class="header-anchor">#</a> 2.3.1 soda安装</h4> <blockquote><p>大多数Golang软件包的安装都是典型的，但是我们还将安装soda实用程序，该实用程序将促进数据库迁移和模型创建。</p></blockquote> <p><strong>不需要使用sqlite 3数据库支持，例如使用mysql，执行以下命令安装soda</strong></p> <div class="language-shell line-numbers-mode"><pre class="language-shell"><code>$ go get github.com/gobuffalo/pop/<span class="token punctuation">..</span>.
$ go <span class="token function">install</span> github.com/gobuffalo/pop/soda
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><p><strong>需要sqlite 3支持（需要GCC或等效的C编译器），执行以下命令安装：</strong></p> <div class="language-shell line-numbers-mode"><pre class="language-shell"><code>$ go get -u -v -tags sqlite github.com/gobuffalo/pop/<span class="token punctuation">..</span>.
$ go <span class="token function">install</span> -tags sqlite github.com/gobuffalo/pop/soda
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><p><strong>如果您不使用构建代码buffalo build，则在构建程序时还必须传递-tags sqlite给go build。</strong></p> <h4 id="_2-3-2-pop配置"><a href="#_2-3-2-pop配置" class="header-anchor">#</a> 2.3.2 pop配置</h4> <blockquote><p>通过YAML文件配置弹出。每个节均按环境细分，因此您可以针对每个环境进行配置。在您的项目根目录中，创建文件<code>database.yml</code>或者<code>config/database.yml</code>，或者自定义配置文件。可以通过将-e development标志传递到任何命令中来标识开发环境。</p></blockquote> <div class="language-yaml line-numbers-mode"><pre class="language-yaml"><code><span class="token key atrule">development</span><span class="token punctuation">:</span>
  <span class="token key atrule">dialect</span><span class="token punctuation">:</span> <span class="token string">&quot;mysql&quot;</span>      <span class="token comment">#数据库类型</span>
  <span class="token key atrule">database</span><span class="token punctuation">:</span> <span class="token string">&quot;kratos&quot;</span>    <span class="token comment">#数据库名称</span>
  <span class="token key atrule">host</span><span class="token punctuation">:</span> <span class="token string">&quot;localhost&quot;</span>     <span class="token comment">#数据库连接地址</span>
  <span class="token key atrule">port</span><span class="token punctuation">:</span> <span class="token string">&quot;3306&quot;</span>          <span class="token comment">#数据库连接端口号</span>
  <span class="token key atrule">user</span><span class="token punctuation">:</span> <span class="token string">&quot;root&quot;</span>          <span class="token comment">#数据库连接用户名账号</span>
  <span class="token key atrule">password</span><span class="token punctuation">:</span> <span class="token string">&quot;admin&quot;</span>     <span class="token comment">#数据库连接账号密码</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br></div></div><h4 id="_2-3-3-创建模型"><a href="#_2-3-3-创建模型" class="header-anchor">#</a> 2.3.3 创建模型</h4> <p>pop 提供一个实用工具 soda。用 soda 可以创建模型。</p> <div class="language-shell line-numbers-mode"><pre class="language-shell"><code>$ soda generate model user title:string first_name:string last_name:string bio:text -e development
v3.41.1

--<span class="token operator">&gt;</span> models/user.go
--<span class="token operator">&gt;</span> models/user_test.go
--<span class="token operator">&gt;</span> goimports -w models/user.go models/user_test.go
<span class="token operator">&gt;</span> migrations/20191225173819_create_users.up.fizz
<span class="token operator">&gt;</span> migrations/20191225173819_create_users.down.fizz

</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br></div></div><blockquote><p><code>soda</code>创建了两个文件夹：<code>models</code> 和 <code>migrations</code>。用户模型存储在其中 <code>models/user.go</code>，初始迁移存储在 migrations/20191225173819_create_users.up.fizz。fizz 下面会讲到如何使用。</p></blockquote> <h4 id="_2-3-4-创建数据库"><a href="#_2-3-4-创建数据库" class="header-anchor">#</a> 2.3.4 创建数据库</h4> <blockquote><p>1、在执行soda命令根目录下有<code>database.yml</code>或者<code>config/database.yml</code>时，并且数据库服务器正在运行，Soda可以在<code>database.yml</code>使用一个简单的命令在文件中创建所有数据库，如下：
-e development 代表创建开发环境下的数据库，当然也可以是 test 和 production。</p></blockquote> <div class="language-shell line-numbers-mode"><pre class="language-shell"><code>$ soda create -e development
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><blockquote><p>2、在执行soda命令根目录下 <strong>没有<code>database.yml</code>或者<code>config/database.yml</code></strong>  时，则必须指定配置文件路径创建数据库，如下</p></blockquote> <div class="language-shell line-numbers-mode"><pre class="language-shell"><code>soda create -e development -c ./contrib/sql/.soda.yml
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h4 id="_2-3-5-完成-fizz"><a href="#_2-3-5-完成-fizz" class="header-anchor">#</a> 2.3.5 完成 fizz</h4> <blockquote><p>编辑 migrations/20191225173819_create_users.up.fizz 文件,下面代码相当于创建一张<code>user</code>表 然后添加两条数据。
具体数据操作语法请参考<a href="https://gobuffalo.io/en/docs/db/fizz/" target="_blank" rel="noopener noreferrer">gobuffalo官网<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></p></blockquote> <div class="language-shell line-numbers-mode"><pre class="language-shell"><code>create_table<span class="token punctuation">(</span><span class="token string">&quot;users&quot;</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    t.Column<span class="token punctuation">(</span><span class="token string">&quot;id&quot;</span>, <span class="token string">&quot;uuid&quot;</span>, <span class="token punctuation">{</span>primary: true<span class="token punctuation">}</span><span class="token punctuation">)</span>
    t.Timestamps<span class="token punctuation">(</span><span class="token punctuation">)</span>
    t.Column<span class="token punctuation">(</span><span class="token string">&quot;name&quot;</span>, <span class="token string">&quot;string&quot;</span>, <span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">)</span>
    t.Column<span class="token punctuation">(</span><span class="token string">&quot;email&quot;</span>, <span class="token string">&quot;string&quot;</span>, <span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">)</span>
    t.Column<span class="token punctuation">(</span><span class="token string">&quot;password_hash&quot;</span>, <span class="token string">&quot;string&quot;</span>, <span class="token punctuation">{</span><span class="token string">&quot;size&quot;</span>:64<span class="token punctuation">}</span><span class="token punctuation">)</span>
    t.Column<span class="token punctuation">(</span><span class="token string">&quot;register_time&quot;</span>, <span class="token string">&quot;timestamp&quot;</span>, <span class="token punctuation">{</span><span class="token string">&quot;default&quot;</span><span class="token builtin class-name">:</span> null<span class="token punctuation">}</span><span class="token punctuation">)</span>
    t.Column<span class="token punctuation">(</span><span class="token string">&quot;last_login_time&quot;</span>, <span class="token string">&quot;timestamp&quot;</span>, <span class="token punctuation">{</span><span class="token string">&quot;default&quot;</span><span class="token builtin class-name">:</span> null<span class="token punctuation">}</span><span class="token punctuation">)</span>
<span class="token punctuation">}</span>

add_index<span class="token punctuation">(</span><span class="token string">&quot;users&quot;</span>, <span class="token string">&quot;name&quot;</span>, <span class="token punctuation">{</span><span class="token string">&quot;unique&quot;</span><span class="token builtin class-name">:</span> true<span class="token punctuation">}</span><span class="token punctuation">)</span>
add_index<span class="token punctuation">(</span><span class="token string">&quot;users&quot;</span>, <span class="token string">&quot;email&quot;</span>, <span class="token punctuation">{</span><span class="token string">&quot;unique&quot;</span><span class="token builtin class-name">:</span> true<span class="token punctuation">}</span><span class="token punctuation">)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br></div></div><h4 id="_2-3-6-运行迁移"><a href="#_2-3-6-运行迁移" class="header-anchor">#</a> 2.3.6 运行迁移</h4> <blockquote><p>1 在执行soda migrate命令迁移数据时，根目录下有<code>database.yml</code>或者<code>config/database.yml</code>时，并且数据库服务器正在运行，soda可以使用下面命令迁移数据库，迁移的数据表位置在执行soda命令位置的./migrations文件夹下面的所有fizz后缀的文件</p></blockquote> <div class="language-shell line-numbers-mode"><pre class="language-shell"><code>soda migrate up -e development
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><blockquote><p>2 在执行soda migrate命令迁移数据时，根目录下 <strong>没有<code>database.yml</code>或者<code>config/database.yml</code></strong> 时，则必须指定迁移配置的yml，迁移的文件路径在自定义的yml目录的./migrations文件夹下面的所有fizz后缀的文件</p></blockquote> <div class="language-shell line-numbers-mode"><pre class="language-shell"><code>soda migrate up -e development -c ./contrib/sql/.soda.yml
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>这样，我们的数据库，数据表都已经创建完成了。</p> <h2 id="_3-golang操作数据库说明"><a href="#_3-golang操作数据库说明" class="header-anchor">#</a> 3 Golang操作数据库说明</h2> <h3 id="_3-1-连接数据库"><a href="#_3-1-连接数据库" class="header-anchor">#</a> 3.1 连接数据库</h3> <div class="language-go line-numbers-mode"><pre class="language-go"><code>tx<span class="token punctuation">,</span> err <span class="token operator">:=</span> pop<span class="token punctuation">.</span><span class="token function">Connect</span><span class="token punctuation">(</span><span class="token string">&quot;development&quot;</span><span class="token punctuation">)</span>
<span class="token keyword">if</span> err <span class="token operator">!=</span> <span class="token boolean">nil</span> <span class="token punctuation">{</span>
    log<span class="token punctuation">.</span><span class="token function">Panic</span><span class="token punctuation">(</span>err<span class="token punctuation">)</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div><h3 id="_3-2-创建新纪录"><a href="#_3-2-创建新纪录" class="header-anchor">#</a> 3.2 创建新纪录</h3> <div class="language-go line-numbers-mode"><pre class="language-go"><code>jessica <span class="token operator">:=</span> models<span class="token punctuation">.</span>User<span class="token punctuation">{</span>
        Title<span class="token punctuation">:</span> <span class="token string">&quot;Ms.&quot;</span><span class="token punctuation">,</span> 
        FirstName<span class="token punctuation">:</span> <span class="token string">&quot;Jessica&quot;</span><span class="token punctuation">,</span> 
        LastName<span class="token punctuation">:</span> <span class="token string">&quot;Jones&quot;</span><span class="token punctuation">,</span> 
        Bio<span class="token punctuation">:</span> <span class="token string">&quot;Private security, super hero.&quot;</span><span class="token punctuation">,</span>
    <span class="token punctuation">}</span>
    <span class="token boolean">_</span><span class="token punctuation">,</span> err <span class="token operator">=</span> tx<span class="token punctuation">.</span><span class="token function">ValidateAndSave</span><span class="token punctuation">(</span><span class="token operator">&amp;</span>jessica<span class="token punctuation">)</span>
    <span class="token keyword">if</span> err <span class="token operator">!=</span> <span class="token boolean">nil</span> <span class="token punctuation">{</span>
        log<span class="token punctuation">.</span><span class="token function">Panic</span><span class="token punctuation">(</span>err<span class="token punctuation">)</span>
    <span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br></div></div><h3 id="_3-3-按-id-查询一条记录"><a href="#_3-3-按-id-查询一条记录" class="header-anchor">#</a> 3.3 按 ID 查询一条记录</h3> <div class="language-go line-numbers-mode"><pre class="language-go"><code>  id <span class="token operator">:=</span> <span class="token string">&quot;240ec3c5-019d-4031-9c27-8a553e022297&quot;</span>
    frank <span class="token operator">:=</span> models<span class="token punctuation">.</span>User<span class="token punctuation">{</span><span class="token punctuation">}</span>
    err <span class="token operator">=</span> tx<span class="token punctuation">.</span><span class="token function">Find</span><span class="token punctuation">(</span><span class="token operator">&amp;</span>frank<span class="token punctuation">,</span> id<span class="token punctuation">)</span>
    <span class="token keyword">if</span> err <span class="token operator">!=</span> <span class="token boolean">nil</span> <span class="token punctuation">{</span>
        fmt<span class="token punctuation">.</span><span class="token function">Print</span><span class="token punctuation">(</span><span class="token string">&quot;ERROR!\n&quot;</span><span class="token punctuation">)</span>
        fmt<span class="token punctuation">.</span><span class="token function">Printf</span><span class="token punctuation">(</span><span class="token string">&quot;%v\n&quot;</span><span class="token punctuation">,</span> err<span class="token punctuation">)</span>
    <span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token punctuation">{</span>
        fmt<span class="token punctuation">.</span><span class="token function">Print</span><span class="token punctuation">(</span><span class="token string">&quot;Success!\n&quot;</span><span class="token punctuation">)</span>
        fmt<span class="token punctuation">.</span><span class="token function">Printf</span><span class="token punctuation">(</span><span class="token string">&quot;%v\n&quot;</span><span class="token punctuation">,</span> frank<span class="token punctuation">)</span>
    <span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br></div></div><h3 id="_3-4-查询所有记录"><a href="#_3-4-查询所有记录" class="header-anchor">#</a> 3.4 查询所有记录</h3> <div class="language-go line-numbers-mode"><pre class="language-go"><code>users <span class="token operator">:=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span>models<span class="token punctuation">.</span>User<span class="token punctuation">{</span><span class="token punctuation">}</span>
    err <span class="token operator">=</span> tx<span class="token punctuation">.</span><span class="token function">All</span><span class="token punctuation">(</span><span class="token operator">&amp;</span>users<span class="token punctuation">)</span>
    <span class="token keyword">if</span> err <span class="token operator">!=</span> <span class="token boolean">nil</span> <span class="token punctuation">{</span>
        fmt<span class="token punctuation">.</span><span class="token function">Print</span><span class="token punctuation">(</span><span class="token string">&quot;ERROR!\n&quot;</span><span class="token punctuation">)</span>
        fmt<span class="token punctuation">.</span><span class="token function">Printf</span><span class="token punctuation">(</span><span class="token string">&quot;%v\n&quot;</span><span class="token punctuation">,</span> err<span class="token punctuation">)</span>
    <span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token punctuation">{</span>
        fmt<span class="token punctuation">.</span><span class="token function">Print</span><span class="token punctuation">(</span><span class="token string">&quot;Success!\n&quot;</span><span class="token punctuation">)</span>
        fmt<span class="token punctuation">.</span><span class="token function">Printf</span><span class="token punctuation">(</span><span class="token string">&quot;%v\n&quot;</span><span class="token punctuation">,</span> users<span class="token punctuation">)</span>
    <span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br></div></div><h3 id="_3-5-模糊查询某些数据"><a href="#_3-5-模糊查询某些数据" class="header-anchor">#</a> 3.5 模糊查询某些数据</h3> <div class="language-go line-numbers-mode"><pre class="language-go"><code>query <span class="token operator">:=</span> tx<span class="token punctuation">.</span><span class="token function">Where</span><span class="token punctuation">(</span><span class="token string">&quot;last_name = 'Rand' OR last_name = 'Murdock'&quot;</span><span class="token punctuation">)</span>
    users <span class="token operator">:=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span>models<span class="token punctuation">.</span>User<span class="token punctuation">{</span><span class="token punctuation">}</span>
    err <span class="token operator">=</span> query<span class="token punctuation">.</span><span class="token function">All</span><span class="token punctuation">(</span><span class="token operator">&amp;</span>users<span class="token punctuation">)</span>
    <span class="token keyword">if</span> err <span class="token operator">!=</span> <span class="token boolean">nil</span> <span class="token punctuation">{</span>
        fmt<span class="token punctuation">.</span><span class="token function">Print</span><span class="token punctuation">(</span><span class="token string">&quot;ERROR!\n&quot;</span><span class="token punctuation">)</span>
        fmt<span class="token punctuation">.</span><span class="token function">Printf</span><span class="token punctuation">(</span><span class="token string">&quot;%v\n&quot;</span><span class="token punctuation">,</span> err<span class="token punctuation">)</span>
    <span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token punctuation">{</span>
        fmt<span class="token punctuation">.</span><span class="token function">Print</span><span class="token punctuation">(</span><span class="token string">&quot;Success!\n&quot;</span><span class="token punctuation">)</span>
        fmt<span class="token punctuation">.</span><span class="token function">Printf</span><span class="token punctuation">(</span><span class="token string">&quot;%v\n&quot;</span><span class="token punctuation">,</span> users<span class="token punctuation">)</span>
    <span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br></div></div><h3 id="_3-6-更新单个记录"><a href="#_3-6-更新单个记录" class="header-anchor">#</a> 3.6 更新单个记录</h3> <div class="language-go line-numbers-mode"><pre class="language-go"><code> query <span class="token operator">:=</span> tx<span class="token punctuation">.</span><span class="token function">Where</span><span class="token punctuation">(</span><span class="token string">&quot;title = 'Ms.'&quot;</span><span class="token punctuation">)</span>
    users <span class="token operator">:=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span>models<span class="token punctuation">.</span>User<span class="token punctuation">{</span><span class="token punctuation">}</span>
    err <span class="token operator">=</span> query<span class="token punctuation">.</span><span class="token function">All</span><span class="token punctuation">(</span><span class="token operator">&amp;</span>users<span class="token punctuation">)</span>
    <span class="token keyword">if</span> err <span class="token operator">!=</span> <span class="token boolean">nil</span> <span class="token punctuation">{</span>
        fmt<span class="token punctuation">.</span><span class="token function">Print</span><span class="token punctuation">(</span><span class="token string">&quot;ERROR!\n&quot;</span><span class="token punctuation">)</span>
        fmt<span class="token punctuation">.</span><span class="token function">Printf</span><span class="token punctuation">(</span><span class="token string">&quot;%v\n&quot;</span><span class="token punctuation">,</span> err<span class="token punctuation">)</span>
    <span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token punctuation">{</span>
        <span class="token keyword">for</span> i <span class="token operator">:=</span> <span class="token number">0</span><span class="token punctuation">;</span> i <span class="token operator">&lt;</span> <span class="token function">len</span><span class="token punctuation">(</span>users<span class="token punctuation">)</span><span class="token punctuation">;</span> i<span class="token operator">++</span> <span class="token punctuation">{</span>
            user <span class="token operator">:=</span> users<span class="token punctuation">[</span>i<span class="token punctuation">]</span>
            user<span class="token punctuation">.</span>Title <span class="token operator">=</span> <span class="token string">&quot;Mrs.&quot;</span>
            tx<span class="token punctuation">.</span><span class="token function">ValidateAndSave</span><span class="token punctuation">(</span><span class="token operator">&amp;</span>user<span class="token punctuation">)</span>
            fmt<span class="token punctuation">.</span><span class="token function">Print</span><span class="token punctuation">(</span><span class="token string">&quot;Success!\n&quot;</span><span class="token punctuation">)</span>
            fmt<span class="token punctuation">.</span><span class="token function">Printf</span><span class="token punctuation">(</span><span class="token string">&quot;%v\n&quot;</span><span class="token punctuation">,</span> user<span class="token punctuation">)</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br></div></div><h3 id="_3-7-更新多个记录"><a href="#_3-7-更新多个记录" class="header-anchor">#</a> 3.7 更新多个记录</h3> <p>更新多个记录与更新单个记录非常相似</p> <div class="language-go line-numbers-mode"><pre class="language-go"><code>users <span class="token operator">:=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span>models<span class="token punctuation">.</span>User<span class="token punctuation">{</span><span class="token punctuation">}</span>
    err <span class="token operator">=</span> tx<span class="token punctuation">.</span><span class="token function">All</span><span class="token punctuation">(</span><span class="token operator">&amp;</span>users<span class="token punctuation">)</span>
    <span class="token keyword">if</span> err <span class="token operator">!=</span> <span class="token boolean">nil</span> <span class="token punctuation">{</span>
        fmt<span class="token punctuation">.</span><span class="token function">Print</span><span class="token punctuation">(</span><span class="token string">&quot;ERROR!\n&quot;</span><span class="token punctuation">)</span>
        fmt<span class="token punctuation">.</span><span class="token function">Printf</span><span class="token punctuation">(</span><span class="token string">&quot;%v\n&quot;</span><span class="token punctuation">,</span> err<span class="token punctuation">)</span>
    <span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token punctuation">{</span>
        <span class="token keyword">for</span> i <span class="token operator">:=</span> <span class="token number">0</span><span class="token punctuation">;</span> i <span class="token operator">&lt;</span> <span class="token function">len</span><span class="token punctuation">(</span>users<span class="token punctuation">)</span><span class="token punctuation">;</span> i<span class="token operator">++</span> <span class="token punctuation">{</span>
            user <span class="token operator">:=</span> users<span class="token punctuation">[</span>i<span class="token punctuation">]</span>
            user<span class="token punctuation">.</span>Location <span class="token operator">=</span> <span class="token string">&quot;NYC, NY&quot;</span>
            tx<span class="token punctuation">.</span><span class="token function">ValidateAndSave</span><span class="token punctuation">(</span><span class="token operator">&amp;</span>user<span class="token punctuation">)</span>
            fmt<span class="token punctuation">.</span><span class="token function">Print</span><span class="token punctuation">(</span><span class="token string">&quot;Success!\n&quot;</span><span class="token punctuation">)</span>
            fmt<span class="token punctuation">.</span><span class="token function">Printf</span><span class="token punctuation">(</span><span class="token string">&quot;%v\n&quot;</span><span class="token punctuation">,</span> user<span class="token punctuation">)</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br></div></div><h3 id="_3-8-删除单个记录"><a href="#_3-8-删除单个记录" class="header-anchor">#</a> 3.8 删除单个记录</h3> <div class="language-go line-numbers-mode"><pre class="language-go"><code>  id <span class="token operator">:=</span> <span class="token string">&quot;240ec3c5-019d-4031-9c27-8a553e022297&quot;</span>
    frank <span class="token operator">:=</span> models<span class="token punctuation">.</span>User<span class="token punctuation">{</span><span class="token punctuation">}</span>
    err <span class="token operator">=</span> tx<span class="token punctuation">.</span><span class="token function">Find</span><span class="token punctuation">(</span><span class="token operator">&amp;</span>frank<span class="token punctuation">,</span> id<span class="token punctuation">)</span>
    <span class="token keyword">if</span> err <span class="token operator">!=</span> <span class="token boolean">nil</span> <span class="token punctuation">{</span>
        fmt<span class="token punctuation">.</span><span class="token function">Print</span><span class="token punctuation">(</span><span class="token string">&quot;ERROR!\n&quot;</span><span class="token punctuation">)</span>
        fmt<span class="token punctuation">.</span><span class="token function">Printf</span><span class="token punctuation">(</span><span class="token string">&quot;%v\n&quot;</span><span class="token punctuation">,</span> err<span class="token punctuation">)</span>
    <span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token punctuation">{</span>
        fmt<span class="token punctuation">.</span><span class="token function">Print</span><span class="token punctuation">(</span><span class="token string">&quot;Success! - Now delete it.\n&quot;</span><span class="token punctuation">)</span>
        tx<span class="token punctuation">.</span><span class="token function">Destroy</span><span class="token punctuation">(</span><span class="token operator">&amp;</span>frank<span class="token punctuation">)</span>
    <span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br></div></div><h2 id="_4-迁移kratos项目的数据到mysql"><a href="#_4-迁移kratos项目的数据到mysql" class="header-anchor">#</a> 4 迁移kratos项目的数据到mysql</h2> <blockquote><p><strong>备注：从这里开始使用Goland编译器来操作kratos项目</strong></p></blockquote> <h3 id="_4-1-用navicat创建一个数据库kratos"><a href="#_4-1-用navicat创建一个数据库kratos" class="header-anchor">#</a> 4.1 用Navicat创建一个数据库kratos</h3> <p><a data-fancybox="" title="创建数据库kratos" href="/img/goImage/kratos3.png"><img src="/img/goImage/kratos3.png" alt="创建数据库kratos"></a></p> <h3 id="_4-2-进行kratos项目数据迁移"><a href="#_4-2-进行kratos项目数据迁移" class="header-anchor">#</a> 4.2 进行kratos项目数据迁移</h3> <h4 id="_4-2-1-项目路径在-gopath-src-kratos-persistence-sql"><a href="#_4-2-1-项目路径在-gopath-src-kratos-persistence-sql" class="header-anchor">#</a> 4.2.1 项目路径在<code>%GOPATH%\src\kratos\persistence\sql\</code></h4> <p><a data-fancybox="" title="kratos项目数据迁移准备" href="/img/goImage/newkratos1.png"><img src="/img/goImage/newkratos1.png" alt="kratos项目数据迁移准备"></a></p> <h4 id="_4-2-2-输入以下命令，对数据库运行所有-向上-迁移"><a href="#_4-2-2-输入以下命令，对数据库运行所有-向上-迁移" class="header-anchor">#</a> 4.2.2 输入以下命令，对数据库运行所有“向上”迁移</h4> <div class="language-shell line-numbers-mode"><pre class="language-shell"><code>soda migrate up -e development -c ./persistence/sql/.soda.yml
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p><a data-fancybox="" title="对数据库运行所有“向上”迁移" href="/img/goImage/kratos5.png"><img src="/img/goImage/kratos5.png" alt="对数据库运行所有“向上”迁移"></a></p> <h4 id="_4-2-3-在navicat查看是否迁移成功"><a href="#_4-2-3-在navicat查看是否迁移成功" class="header-anchor">#</a> 4.2.3 在Navicat查看是否迁移成功</h4> <p><a data-fancybox="" title="查看是否迁移成功" href="/img/goImage/kratos6.png"><img src="/img/goImage/kratos6.png" alt="查看是否迁移成功"></a></p> <h4 id="_4-2-4-修改kratos的配置文件数据连接"><a href="#_4-2-4-修改kratos的配置文件数据连接" class="header-anchor">#</a> 4.2.4 修改kratos的配置文件数据连接</h4> <p>路径在<code>$GOPATH$\src\kratos\docs\.kratos.yaml</code> <a data-fancybox="" title=" 修改kratos的配置文件" href="/img/goImage/kratos7.png"><img src="/img/goImage/kratos7.png" alt=" 修改kratos的配置文件"></a></p> <h2 id="_5-编译kratos"><a href="#_5-编译kratos" class="header-anchor">#</a> 5 编译kratos</h2> <div class="language-shell line-numbers-mode"><pre class="language-shell"><code><span class="token number">1</span> <span class="token string">&quot;win+R&quot;</span>打开运行。
<span class="token number">2</span> 输入<span class="token string">&quot;cmd&quot;</span>回车进入命令提示符。
<span class="token number">3</span> 进入到kratos对应目录下（本机为D:<span class="token punctuation">\</span>go_project<span class="token punctuation">\</span>src<span class="token punctuation">\</span>kratos）
<span class="token number">4</span> 输入go build main.go
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div><p><a data-fancybox="" title="进入到kratos对应目录" href="/img/goImage/kratos2.png"><img src="/img/goImage/kratos2.png" alt="进入到kratos对应目录"></a></p> <h2 id="_6-启动kratos项目"><a href="#_6-启动kratos项目" class="header-anchor">#</a> 6 启动kratos项目</h2> <p>在Goland进入<code>%GOPATH%/src/kratos</code>目录执行以下命令启动项目</p> <div class="language-cmd line-numbers-mode"><pre class="language-text"><code>main.exe serve -c ./docs/.kratos.yaml
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p><a data-fancybox="" title="kratos项目启动成功界面" href="/img/goImage/kratos8.png"><img src="/img/goImage/kratos8.png" alt="kratos项目启动成功界面"></a></p> <h2 id="_7-绑定前端页面"><a href="#_7-绑定前端页面" class="header-anchor">#</a> 7 绑定前端页面</h2> <p><a href="https://github.com/ory/kratos-selfservice-ui-node" target="_blank" rel="noopener noreferrer">kratos前端页面地址下载<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></p> <h3 id="_7-1-前端文件结构说明"><a href="#_7-1-前端文件结构说明" class="header-anchor">#</a> 7.1 前端文件结构说明</h3> <p><a data-fancybox="" title="kratos-ui-node" href="/img/blogImage/kratos-ui-node.png"><img src="/img/blogImage/kratos-ui-node.png" alt="kratos-ui-node"></a></p> <h3 id="_7-2-前端启动"><a href="#_7-2-前端启动" class="header-anchor">#</a> 7.2 前端启动</h3> <p>若没有安装nodejs请自行百度安装</p> <div class="language-shell script line-numbers-mode"><pre class="language-shell"><code>//1 下载前端依赖包
 <span class="token function">npm</span> i

//2 修改配置文件 kratos-selfservice-ui-node/src/config.ts
//修改对应的后端地址ip 如图7.1

//3 启动前端页面服务
<span class="token function">npm</span> run start 
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br></div></div><h2 id="_8-后台数据库说明"><a href="#_8-后台数据库说明" class="header-anchor">#</a> 8 后台数据库说明</h2> <h3 id="_8-1-邮件消息表courier-messages"><a href="#_8-1-邮件消息表courier-messages" class="header-anchor">#</a> 8.1 邮件消息表courier_messages</h3> <table><thead><tr><th style="text-align:left;">字段名称</th> <th style="text-align:left;">字段类型</th> <th style="text-align:left;">参数说明</th></tr></thead> <tbody><tr><td style="text-align:left;">id</td> <td style="text-align:left;">char(36)</td> <td style="text-align:left;">主键id</td></tr> <tr><td style="text-align:left;">type</td> <td style="text-align:left;">int(11)</td> <td style="text-align:left;">邮件类型</td></tr> <tr><td style="text-align:left;">status</td> <td style="text-align:left;">int(11)</td> <td style="text-align:left;">邮件状态</td></tr> <tr><td style="text-align:left;">body</td> <td style="text-align:left;">varchar(255)</td> <td style="text-align:left;">邮件主体内容</td></tr> <tr><td style="text-align:left;">subject</td> <td style="text-align:left;">varchar(255)</td> <td style="text-align:left;">邮件主题</td></tr> <tr><td style="text-align:left;">recipient</td> <td style="text-align:left;">varchar(255)</td> <td style="text-align:left;">收件人信息</td></tr> <tr><td style="text-align:left;">created_at</td> <td style="text-align:left;">datetime</td> <td style="text-align:left;">创建时间</td></tr> <tr><td style="text-align:left;">updated_at</td> <td style="text-align:left;">datetime</td> <td style="text-align:left;">修改时间</td></tr></tbody></table> <h3 id="_8-2-身份表identities"><a href="#_8-2-身份表identities" class="header-anchor">#</a> 8.2 身份表identities</h3> <table><thead><tr><th style="text-align:left;">字段名称</th> <th style="text-align:left;">字段类型</th> <th style="text-align:left;">参数说明</th></tr></thead> <tbody><tr><td style="text-align:left;">id</td> <td style="text-align:left;">char(36)</td> <td style="text-align:left;">主键id</td></tr> <tr><td style="text-align:left;">traits_schema_id</td> <td style="text-align:left;">varchar(2048)</td> <td style="text-align:left;">特征模式id</td></tr> <tr><td style="text-align:left;">traits</td> <td style="text-align:left;">json</td> <td style="text-align:left;">个性特征</td></tr> <tr><td style="text-align:left;">created_at</td> <td style="text-align:left;">datetime</td> <td style="text-align:left;">创建时间</td></tr> <tr><td style="text-align:left;">updated_at</td> <td style="text-align:left;">datetime</td> <td style="text-align:left;">修改时间</td></tr></tbody></table> <h3 id="_8-3-身份标识符"><a href="#_8-3-身份标识符" class="header-anchor">#</a> 8.3 身份标识符</h3> <p>身份标识符数据表<code>identity_credential_identifiers</code></p> <table><thead><tr><th style="text-align:left;">字段名称</th> <th style="text-align:left;">字段类型</th> <th style="text-align:left;">参数说明</th></tr></thead> <tbody><tr><td style="text-align:left;">id</td> <td style="text-align:left;">char(36)</td> <td style="text-align:left;">主键id</td></tr> <tr><td style="text-align:left;">identifier</td> <td style="text-align:left;">varchar(255)</td> <td style="text-align:left;">身份描述</td></tr> <tr><td style="text-align:left;">identity_credential_id</td> <td style="text-align:left;">char(36)</td> <td style="text-align:left;">identity_credentials主键id</td></tr> <tr><td style="text-align:left;">created_at</td> <td style="text-align:left;">datetime</td> <td style="text-align:left;">创建时间</td></tr> <tr><td style="text-align:left;">updated_at</td> <td style="text-align:left;">datetime</td> <td style="text-align:left;">修改时间</td></tr></tbody></table> <h3 id="_8-4-身份类型"><a href="#_8-4-身份类型" class="header-anchor">#</a> 8.4 身份类型</h3> <p>身份证类型数据表<code>identity_credential_types</code></p> <table><thead><tr><th style="text-align:left;">字段名称</th> <th style="text-align:left;">字段类型</th> <th style="text-align:left;">参数说明</th></tr></thead> <tbody><tr><td style="text-align:left;">id</td> <td style="text-align:left;">char(36)</td> <td style="text-align:left;">主键id</td></tr> <tr><td style="text-align:left;">name</td> <td style="text-align:left;">varchar(32)</td> <td style="text-align:left;">身份名称</td></tr></tbody></table> <h3 id="_8-5-身份证数据表"><a href="#_8-5-身份证数据表" class="header-anchor">#</a> 8.5 身份证数据表</h3> <p>身份证数据表<code>identity_credentials</code></p> <table><thead><tr><th style="text-align:left;">字段名称</th> <th style="text-align:left;">字段类型</th> <th style="text-align:left;">参数说明</th></tr></thead> <tbody><tr><td style="text-align:left;">id</td> <td style="text-align:left;">char(36)</td> <td style="text-align:left;">主键id</td></tr> <tr><td style="text-align:left;">config</td> <td style="text-align:left;">json</td> <td style="text-align:left;">身份配置</td></tr> <tr><td style="text-align:left;">identity_credential_type_id</td> <td style="text-align:left;">char(36)</td> <td style="text-align:left;">identity_credential_type主键id</td></tr> <tr><td style="text-align:left;">identity_id</td> <td style="text-align:left;">char(36)</td> <td style="text-align:left;">identities外键</td></tr> <tr><td style="text-align:left;">created_at</td> <td style="text-align:left;">datetime</td> <td style="text-align:left;">创建时间</td></tr> <tr><td style="text-align:left;">updated_at</td> <td style="text-align:left;">datetime</td> <td style="text-align:left;">修改时间</td></tr></tbody></table> <h3 id="_8-6-迁移记录表"><a href="#_8-6-迁移记录表" class="header-anchor">#</a> 8.6 迁移记录表</h3> <p>迁移记录表<code>schema_migration</code></p> <table><thead><tr><th style="text-align:left;">字段名称</th> <th style="text-align:left;">字段类型</th> <th style="text-align:left;">参数说明</th></tr></thead> <tbody><tr><td style="text-align:left;">version</td> <td style="text-align:left;">varchar(14)</td> <td style="text-align:left;">迁移版本号</td></tr></tbody></table> <h3 id="_8-7-自助服务错误表"><a href="#_8-7-自助服务错误表" class="header-anchor">#</a> 8.7 自助服务错误表</h3> <p>自助服务错误表<code>selfservice_errors</code></p> <table><thead><tr><th style="text-align:left;">字段名称</th> <th style="text-align:left;">字段类型</th> <th style="text-align:left;">参数说明</th></tr></thead> <tbody><tr><td style="text-align:left;">id</td> <td style="text-align:left;">char(36)</td> <td style="text-align:left;">主键id</td></tr> <tr><td style="text-align:left;">errors</td> <td style="text-align:left;">json</td> <td style="text-align:left;">错误信息</td></tr> <tr><td style="text-align:left;">seen_at</td> <td style="text-align:left;">datetime</td> <td style="text-align:left;">查看时间</td></tr> <tr><td style="text-align:left;">was_seen</td> <td style="text-align:left;">tinyint(1)</td> <td style="text-align:left;">是否查看信息0未查看 1已查看</td></tr> <tr><td style="text-align:left;">created_at</td> <td style="text-align:left;">datetime</td> <td style="text-align:left;">创建时间</td></tr> <tr><td style="text-align:left;">updated_at</td> <td style="text-align:left;">datetime</td> <td style="text-align:left;">修改时间</td></tr> <tr><td style="text-align:left;">csrf_token</td> <td style="text-align:left;">varchar(255)</td> <td style="text-align:left;">token数据</td></tr></tbody></table> <h3 id="_8-8-登录请求方法记录表"><a href="#_8-8-登录请求方法记录表" class="header-anchor">#</a> 8.8 登录请求方法记录表</h3> <p>自助服务登录请求方法记录表<code>selfservice_login_request_methods</code></p> <table><thead><tr><th style="text-align:left;">字段名称</th> <th style="text-align:left;">字段类型</th> <th style="text-align:left;">参数说明</th></tr></thead> <tbody><tr><td style="text-align:left;">id</td> <td style="text-align:left;">char(36)</td> <td style="text-align:left;">主键id</td></tr> <tr><td style="text-align:left;">method</td> <td style="text-align:left;">varchar(32)</td> <td style="text-align:left;">请求方法</td></tr> <tr><td style="text-align:left;">selfservice_login_request_id</td> <td style="text-align:left;">char(36)</td> <td style="text-align:left;">selfservice_login_requests表主键id</td></tr> <tr><td style="text-align:left;">config</td> <td style="text-align:left;">json</td> <td style="text-align:left;">请求方法配置信息</td></tr> <tr><td style="text-align:left;">created_at</td> <td style="text-align:left;">datetime</td> <td style="text-align:left;">创建时间</td></tr> <tr><td style="text-align:left;">updated_at</td> <td style="text-align:left;">datetime</td> <td style="text-align:left;">修改时间</td></tr></tbody></table> <h3 id="_8-9-登录请求记录表"><a href="#_8-9-登录请求记录表" class="header-anchor">#</a> 8.9 登录请求记录表</h3> <p>自助服务登录请求记录表<code>selfservice_login_requests</code></p> <table><thead><tr><th style="text-align:left;">字段名称</th> <th style="text-align:left;">字段类型</th> <th style="text-align:left;">参数说明</th></tr></thead> <tbody><tr><td style="text-align:left;">id</td> <td style="text-align:left;">char(36)</td> <td style="text-align:left;">主键id</td></tr> <tr><td style="text-align:left;">request_url</td> <td style="text-align:left;">varchar(2048)</td> <td style="text-align:left;">请求的httpUrl</td></tr> <tr><td style="text-align:left;">issued_at</td> <td style="text-align:left;">datetime</td> <td style="text-align:left;">触发请求时间</td></tr> <tr><td style="text-align:left;">expires_at</td> <td style="text-align:left;">datetime</td> <td style="text-align:left;">过期时间</td></tr> <tr><td style="text-align:left;">active_method</td> <td style="text-align:left;">varchar(32)</td> <td style="text-align:left;">主动方法</td></tr> <tr><td style="text-align:left;">csrf_token</td> <td style="text-align:left;">varchar(255)</td> <td style="text-align:left;">csrf令牌</td></tr> <tr><td style="text-align:left;">created_at</td> <td style="text-align:left;">datetime</td> <td style="text-align:left;">创建时间</td></tr> <tr><td style="text-align:left;">updated_at</td> <td style="text-align:left;">datetime</td> <td style="text-align:left;">修改时间</td></tr></tbody></table> <h3 id="_8-10-配置文件管理请求"><a href="#_8-10-配置文件管理请求" class="header-anchor">#</a> 8.10 配置文件管理请求</h3> <p>自助服务配置文件管理请求数据表<code>selfservice_profile_management_requests</code></p> <table><thead><tr><th style="text-align:left;">字段名称</th> <th style="text-align:left;">字段类型</th> <th style="text-align:left;">参数说明</th></tr></thead> <tbody><tr><td style="text-align:left;">id</td> <td style="text-align:left;">char(36)</td> <td style="text-align:left;">主键id</td></tr> <tr><td style="text-align:left;">request_url</td> <td style="text-align:left;">varchar(2048)</td> <td style="text-align:left;">请求的httpUrl</td></tr> <tr><td style="text-align:left;">issued_at</td> <td style="text-align:left;">datetime</td> <td style="text-align:left;">触发请求时间</td></tr> <tr><td style="text-align:left;">expires_at</td> <td style="text-align:left;">datetime</td> <td style="text-align:left;">过期时间</td></tr> <tr><td style="text-align:left;">form</td> <td style="text-align:left;">json</td> <td style="text-align:left;">form表单数据</td></tr> <tr><td style="text-align:left;">update_successful</td> <td style="text-align:left;">tinyint(1)</td> <td style="text-align:left;">更新是否成功</td></tr> <tr><td style="text-align:left;">identity_id</td> <td style="text-align:left;">char(36)</td> <td style="text-align:left;">identities主键id</td></tr> <tr><td style="text-align:left;">created_at</td> <td style="text-align:left;">datetime</td> <td style="text-align:left;">创建时间</td></tr> <tr><td style="text-align:left;">updated_at</td> <td style="text-align:left;">datetime</td> <td style="text-align:left;">修改时间</td></tr></tbody></table> <h3 id="_8-11-注册请求方法记录表"><a href="#_8-11-注册请求方法记录表" class="header-anchor">#</a> 8.11 注册请求方法记录表</h3> <p>自助服务注册请求方法记录表<code>selfservice_registration_request_methods</code></p> <table><thead><tr><th style="text-align:left;">字段名称</th> <th style="text-align:left;">字段类型</th> <th style="text-align:left;">参数说明</th></tr></thead> <tbody><tr><td style="text-align:left;">id</td> <td style="text-align:left;">char(36)</td> <td style="text-align:left;">主键id</td></tr> <tr><td style="text-align:left;">method</td> <td style="text-align:left;">varchar(32)</td> <td style="text-align:left;">请求方法</td></tr> <tr><td style="text-align:left;">selfservice_registration_request_id</td> <td style="text-align:left;">char(36)</td> <td style="text-align:left;">selfservice_registration_requests表主键id</td></tr> <tr><td style="text-align:left;">config</td> <td style="text-align:left;">json</td> <td style="text-align:left;">请求方法配置信息</td></tr> <tr><td style="text-align:left;">created_at</td> <td style="text-align:left;">datetime</td> <td style="text-align:left;">创建时间</td></tr> <tr><td style="text-align:left;">updated_at</td> <td style="text-align:left;">datetime</td> <td style="text-align:left;">修改时间</td></tr></tbody></table> <h3 id="_8-12-注册请求记录表"><a href="#_8-12-注册请求记录表" class="header-anchor">#</a> 8.12 注册请求记录表</h3> <p>自助服务注册请求记录表<code>selfservice_registration_requests</code></p> <table><thead><tr><th style="text-align:left;">字段名称</th> <th style="text-align:left;">字段类型</th> <th style="text-align:left;">参数说明</th></tr></thead> <tbody><tr><td style="text-align:left;">id</td> <td style="text-align:left;">char(36)</td> <td style="text-align:left;">主键id</td></tr> <tr><td style="text-align:left;">request_url</td> <td style="text-align:left;">varchar(2048)</td> <td style="text-align:left;">请求的httpUrl</td></tr> <tr><td style="text-align:left;">issued_at</td> <td style="text-align:left;">datetime</td> <td style="text-align:left;">触发请求时间</td></tr> <tr><td style="text-align:left;">expires_at</td> <td style="text-align:left;">datetime</td> <td style="text-align:left;">过期时间</td></tr> <tr><td style="text-align:left;">active_method</td> <td style="text-align:left;">varchar(32)</td> <td style="text-align:left;">主动方法</td></tr> <tr><td style="text-align:left;">csrf_token</td> <td style="text-align:left;">varchar(255)</td> <td style="text-align:left;">csrf令牌</td></tr> <tr><td style="text-align:left;">created_at</td> <td style="text-align:left;">datetime</td> <td style="text-align:left;">创建时间</td></tr> <tr><td style="text-align:left;">updated_at</td> <td style="text-align:left;">datetime</td> <td style="text-align:left;">修改时间</td></tr></tbody></table> <h3 id="_8-13-sessions"><a href="#_8-13-sessions" class="header-anchor">#</a> 8.13 sessions</h3> <table><thead><tr><th style="text-align:left;">字段名称</th> <th style="text-align:left;">字段类型</th> <th style="text-align:left;">参数说明</th></tr></thead> <tbody><tr><td style="text-align:left;">id</td> <td style="text-align:left;">char(36)</td> <td style="text-align:left;">主键id</td></tr> <tr><td style="text-align:left;">issued_at</td> <td style="text-align:left;">datetime</td> <td style="text-align:left;">触发请求时间</td></tr> <tr><td style="text-align:left;">expires_at</td> <td style="text-align:left;">datetime</td> <td style="text-align:left;">过期时间</td></tr> <tr><td style="text-align:left;">authenticated_at</td> <td style="text-align:left;">datetime</td> <td style="text-align:left;">授权时间</td></tr> <tr><td style="text-align:left;">identity_id</td> <td style="text-align:left;">char(36)</td> <td style="text-align:left;">identities主键id</td></tr> <tr><td style="text-align:left;">created_at</td> <td style="text-align:left;">datetime</td> <td style="text-align:left;">创建时间</td></tr> <tr><td style="text-align:left;">updated_at</td> <td style="text-align:left;">datetime</td> <td style="text-align:left;">修改时间</td></tr></tbody></table> <h2 id="_9-kratos项目swagger详解"><a href="#_9-kratos项目swagger详解" class="header-anchor">#</a> 9 Kratos项目swagger详解</h2> <p><a href="/go/middleware/go-swagger.html" style="display:block;margin-block-start:1em;margin-block-end:1em;margin-inline-start:0px;margin-inline-end:0px;"><strong>swagger安装教程</strong></a></p> <h3 id="_9-1-项目请求api列表"><a href="#_9-1-项目请求api列表" class="header-anchor">#</a> 9.1 项目请求API列表</h3> <details style="display:block;position:relative;border-radius:2px;margin:1.6em 0;padding:1.6em;background-color:#eee;"><summary>点击查看项目所有请求API列表</summary> <div class="language-go line-numbers-mode"><pre class="language-go"><code><span class="token number">1</span> Common 公用的接口
 <span class="token number">1.1</span> 返回登录请求的上下文 请求方式<span class="token punctuation">:</span>GET 
 说明<span class="token punctuation">:</span>通过ORY Kratos的Public API访问此终结点时，请确保已设置cookie，以使CSRF正常运行。
 接口<span class="token punctuation">:</span><span class="token operator">/</span>self<span class="token operator">-</span>service<span class="token operator">/</span>browser<span class="token operator">/</span>flows<span class="token operator">/</span>requests<span class="token operator">/</span>login?request<span class="token operator">=</span><span class="token number">1234</span>

 <span class="token number">1.2</span> 获取基于浏览器的配置文件管理流的请求上下文 请求方式<span class="token punctuation">:</span>GET 
 说明<span class="token punctuation">:</span>通过ORY Kratos的Public API访问此端点时，请确保已设置cookie，因为它们是检查身份验证会话所必需的。
 接口<span class="token punctuation">:</span><span class="token operator">/</span>self<span class="token operator">-</span>service<span class="token operator">/</span>browser<span class="token operator">/</span>flows<span class="token operator">/</span>requests<span class="token operator">/</span>profile

 <span class="token number">1.3</span> 该端点返回注册请求的上下文 请求方式<span class="token punctuation">:</span>GET 
 说明<span class="token punctuation">:</span>通过ORY Kratos的Public API访问此终结点时，请确保已设置cookie，以使CSRF正常运行。
 接口<span class="token punctuation">:</span><span class="token operator">/</span>self<span class="token operator">-</span>service<span class="token operator">/</span>browser<span class="token operator">/</span>flows<span class="token operator">/</span>requests<span class="token operator">/</span>registration

 <span class="token number">1.4</span> 该端点返回与面向用户的自助服务错误相关的错误。 请求方式<span class="token punctuation">:</span>GET 
 接口<span class="token punctuation">:</span><span class="token operator">/</span>self<span class="token operator">-</span>service<span class="token operator">/</span>errors

<span class="token number">2</span>  public
 <span class="token number">2.1</span> 该端点初始化基于浏览器的用户登录流程。 请求方式<span class="token punctuation">:</span>GET 
 接口<span class="token punctuation">:</span><span class="token operator">/</span>self<span class="token operator">-</span>service<span class="token operator">/</span>browser<span class="token operator">/</span>flows<span class="token operator">/</span>login
 说明<span class="token punctuation">:</span>该端点初始化基于浏览器的用户登录流程。初始化后，浏览器将重定向至
  urls<span class="token punctuation">.</span>login_ui请求ID设置为查询参数的浏览器。如果已经存在有效的用户会话，
  则浏览器将重定向到urls<span class="token punctuation">.</span>default_redirect_url。

 <span class="token number">2.2</span> 初始化基于浏览器的注销用户流 请求方式<span class="token punctuation">:</span>GET 
 接口<span class="token punctuation">:</span><span class="token operator">/</span>self<span class="token operator">-</span>service<span class="token operator">/</span>browser<span class="token operator">/</span>flows<span class="token operator">/</span>logout 

 <span class="token number">2.3</span> 初始化基于浏览器的配置文件管理流程 请求方式<span class="token punctuation">:</span>GET 
 接口<span class="token punctuation">:</span><span class="token operator">/</span>self<span class="token operator">-</span>service<span class="token operator">/</span>browser<span class="token operator">/</span>flows<span class="token operator">/</span>profile 

 <span class="token number">2.4</span> 完成基于浏览器的配置文件管理流程 请求方式<span class="token punctuation">:</span>POST 
 接口<span class="token punctuation">:</span><span class="token operator">/</span>self<span class="token operator">-</span>service<span class="token operator">/</span>browser<span class="token operator">/</span>flows<span class="token operator">/</span>profile<span class="token operator">/</span>update

 <span class="token number">2.5</span> 初始化基于浏览器的注册用户流 请求方式<span class="token punctuation">:</span>GET 
 接口<span class="token punctuation">:</span><span class="token operator">/</span>self<span class="token operator">-</span>service<span class="token operator">/</span>browser<span class="token operator">/</span>flows<span class="token operator">/</span>registration

 <span class="token number">2.6</span> 获取基于浏览器的登录用户流的请求上下文 请求方式<span class="token punctuation">:</span>GET 
 接口<span class="token punctuation">:</span><span class="token operator">/</span>self<span class="token operator">-</span>service<span class="token operator">/</span>browser<span class="token operator">/</span>flows<span class="token operator">/</span>requests<span class="token operator">/</span>login 

 <span class="token number">2.7</span> 获取基于浏览器的配置文件管理流的请求上下文 请求方式<span class="token punctuation">:</span>GET 
 接口<span class="token punctuation">:</span><span class="token operator">/</span>self<span class="token operator">-</span>service<span class="token operator">/</span>browser<span class="token operator">/</span>flows<span class="token operator">/</span>requests<span class="token operator">/</span>profile

 <span class="token number">2.8</span> 获取基于浏览器的注册用户流的请求上下文 请求方式<span class="token punctuation">:</span>GET 
 接口<span class="token punctuation">:</span><span class="token operator">/</span>self<span class="token operator">-</span>service<span class="token operator">/</span>browser<span class="token operator">/</span>flows<span class="token operator">/</span>requests<span class="token operator">/</span>registration

 <span class="token number">2.9</span> 此终结点返回与面向用户的自助服务错误相关联的错误 请求方式<span class="token punctuation">:</span>GET 
 接口<span class="token punctuation">:</span><span class="token operator">/</span>self<span class="token operator">-</span>service<span class="token operator">/</span>errors

 <span class="token number">2.10</span> 检查当前HTTP会话属于谁 请求方式<span class="token punctuation">:</span>GET 
 接口<span class="token punctuation">:</span><span class="token operator">/</span>sessions<span class="token operator">/</span>whoami


<span class="token number">3</span> admin 

 <span class="token number">3.1</span> 列出系统中的所有标识 请求方式<span class="token punctuation">:</span>GET 
 接口<span class="token punctuation">:</span><span class="token operator">/</span>identities

 <span class="token number">3.2</span> 创建标识 请求方式<span class="token punctuation">:</span>POST 
 接口<span class="token punctuation">:</span><span class="token operator">/</span>identities

 <span class="token number">3.3</span> 获取对应的标识 请求方式<span class="token punctuation">:</span>GET 
 接口<span class="token punctuation">:</span><span class="token operator">/</span>identities<span class="token operator">/</span><span class="token punctuation">{</span>id<span class="token punctuation">}</span>

 <span class="token number">3.4</span> 修改对应的标识 请求方式<span class="token punctuation">:</span>PUT
 接口<span class="token punctuation">:</span><span class="token operator">/</span>identities<span class="token operator">/</span><span class="token punctuation">{</span>id<span class="token punctuation">}</span>

 <span class="token number">3.5</span> 删除对应的标识 请求方式<span class="token punctuation">:</span>DELETE
 接口<span class="token punctuation">:</span><span class="token operator">/</span>identities<span class="token operator">/</span><span class="token punctuation">{</span>id<span class="token punctuation">}</span>

 <span class="token number">3.6</span> 获取基于浏览器的登录用户流的请求上下文 请求方式<span class="token punctuation">:</span>GET
 接口<span class="token punctuation">:</span><span class="token operator">/</span>self<span class="token operator">-</span>service<span class="token operator">/</span>browser<span class="token operator">/</span>flows<span class="token operator">/</span>requests<span class="token operator">/</span>login

 <span class="token number">3.7</span>获取基于浏览器的配置文件管理流的请求上下文 请求方式<span class="token punctuation">:</span>GET
 接口<span class="token punctuation">:</span><span class="token operator">/</span>self<span class="token operator">-</span>service<span class="token operator">/</span>browser<span class="token operator">/</span>flows<span class="token operator">/</span>requests<span class="token operator">/</span>profile

 <span class="token number">3.8</span> 获取基于浏览器的注册用户流的请求上下文 请求方式<span class="token punctuation">:</span>GET
 接口<span class="token punctuation">:</span><span class="token operator">/</span>self<span class="token operator">-</span>service<span class="token operator">/</span>browser<span class="token operator">/</span>flows<span class="token operator">/</span>requests<span class="token operator">/</span>registration

 <span class="token number">3.9</span> 获取面向用户的自助服务错误 请求方式<span class="token punctuation">:</span>GET
 接口<span class="token punctuation">:</span><span class="token operator">/</span>self<span class="token operator">-</span>service<span class="token operator">/</span>errors

<span class="token number">4</span> health
 <span class="token number">4.1</span> 检查活动状态<span class="token punctuation">,</span>请求方式<span class="token punctuation">:</span>GET 
 接口<span class="token punctuation">:</span><span class="token operator">/</span>health<span class="token operator">/</span>alive

 <span class="token number">4.2</span> 检查准备状态<span class="token punctuation">,</span>请求方式<span class="token punctuation">:</span>GET 
 接口<span class="token punctuation">:</span><span class="token operator">/</span>health<span class="token operator">/</span>ready

<span class="token number">5</span> 获取服务版本 请求方式<span class="token punctuation">:</span>GET 
  接口<span class="token punctuation">:</span><span class="token operator">/</span>version 
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br><span class="line-number">31</span><br><span class="line-number">32</span><br><span class="line-number">33</span><br><span class="line-number">34</span><br><span class="line-number">35</span><br><span class="line-number">36</span><br><span class="line-number">37</span><br><span class="line-number">38</span><br><span class="line-number">39</span><br><span class="line-number">40</span><br><span class="line-number">41</span><br><span class="line-number">42</span><br><span class="line-number">43</span><br><span class="line-number">44</span><br><span class="line-number">45</span><br><span class="line-number">46</span><br><span class="line-number">47</span><br><span class="line-number">48</span><br><span class="line-number">49</span><br><span class="line-number">50</span><br><span class="line-number">51</span><br><span class="line-number">52</span><br><span class="line-number">53</span><br><span class="line-number">54</span><br><span class="line-number">55</span><br><span class="line-number">56</span><br><span class="line-number">57</span><br><span class="line-number">58</span><br><span class="line-number">59</span><br><span class="line-number">60</span><br><span class="line-number">61</span><br><span class="line-number">62</span><br><span class="line-number">63</span><br><span class="line-number">64</span><br><span class="line-number">65</span><br><span class="line-number">66</span><br><span class="line-number">67</span><br><span class="line-number">68</span><br><span class="line-number">69</span><br><span class="line-number">70</span><br><span class="line-number">71</span><br><span class="line-number">72</span><br><span class="line-number">73</span><br><span class="line-number">74</span><br><span class="line-number">75</span><br><span class="line-number">76</span><br><span class="line-number">77</span><br><span class="line-number">78</span><br><span class="line-number">79</span><br><span class="line-number">80</span><br><span class="line-number">81</span><br><span class="line-number">82</span><br><span class="line-number">83</span><br><span class="line-number">84</span><br><span class="line-number">85</span><br><span class="line-number">86</span><br><span class="line-number">87</span><br><span class="line-number">88</span><br><span class="line-number">89</span><br></div></div></details> <h2 id="_10-测试服务"><a href="#_10-测试服务" class="header-anchor">#</a> 10 测试服务</h2> <h3 id="_10-1-跳转登录页面"><a href="#_10-1-跳转登录页面" class="header-anchor">#</a> 10.1 跳转登录页面</h3> <blockquote><p>跳转流程说明
kratos/public/self-service/browser/flows/login</p></blockquote> <h2 id="_11-更多资料参考"><a href="#_11-更多资料参考" class="header-anchor">#</a> 11 更多资料参考</h2> <p><a href="https://github.com/ory/kratos" target="_blank" rel="noopener noreferrer">Kratos源码<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></p> <p><a href="https://www.ory.sh/docs/kratos/" target="_blank" rel="noopener noreferrer">Kratos官网文档<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></p></div> <footer class="page-edit"><!----> <!----></footer> <div class="page-nav"><p class="inner"><span class="prev">
      ←
      <a href="/blog/Go/11  需求规格说明书.html" class="prev">
        权限需求规格说明书
      </a></span> <span class="next"><a href="/blog/Go/13  权限服务器keto.html">
        权限服务器keto
      </a>
      →
    </span></p></div> </main></div><div class="global-ui"><!----></div></div>
    <script src="/assets/js/app.1bc80adb.js" defer></script><script src="/assets/js/2.7c0608ab.js" defer></script><script src="/assets/js/36.961a1c50.js" defer></script>
  </body>
</html>
